package com.itheima03.day16test;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author 刘全
 * @date 2021/8/9
 */
public class ReceiveTest3 {
    public static void main(String[] args) throws IOException {
        /**
         * 3. 使用UDP协议完成数据传输
         *     发送端发送，接收端接收
         */
        DatagramSocket ds = new DatagramSocket(10086);

        byte[] bytes = new byte[1024];

        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

        ds.receive(dp);
        byte[] data = dp.getData();
        System.out.println(new String(data));

        ds.close();
    }
}
